package design_pattern.state.demo01;

import design_pattern.state.demo01.state.State;
import lombok.Data;

/**
 * @version 1.0.0
 * Created by cyd on 2022-06-02 17:41:00
 * @ClassName : design_pattern.state.demo01.Context
 * @Description : 上下文环境类对象，里面包含一个状态，状态会随着request方法的执行依次变化
 */
@Data
public class Context {

    private State state;

    public Context(State state) {
        this.state = state;
        System.out.println("初始化Context，当前状态为：" + state.getClass());
    }

    public void request() {
        System.out.println("Context执行request方法---执行前状态：" + this.getState().getClass());
        state.handleContext(this);
        System.out.println("Context执行request方法---执行后状态：" + this.getState().getClass());
    }
}
